package com.heqq;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

public class RongtongFplc {
    public static void main(String[] args) throws InterruptedException {
        WebDriver driver = new ChromeDriver();

        driver.get("http://192.168.168.14:8080/pages/platform/login/login.html");

        Thread.sleep(1500);
        driver.manage().window().maximize();

        Thread.sleep(2000);
        driver.findElement(By.name("username")).sendKeys(new String[]{"lilm"});

        Thread.sleep(1000);
        driver.findElement(By.name("password")).sendKeys(new String[]{"password"});

        Thread.sleep(2000);
        driver.findElement(By.xpath("//*[@id=\"legion-form\"]/div[3]/div[2]/button")).click();

        Thread.sleep(3000);
        driver.findElement(By.xpath("/html/body/div[2]/div[2]/div[2]/div/div[1]/div[3]")).click();

        Thread.sleep(2000);
        driver.findElement(By.xpath("/html/body/div[2]/div[2]/div[2]/div/div[1]/div[3]/div[3]/div[1]")).click();

        Thread.sleep(2000);
        driver.findElement(By.xpath("/html/body/div[2]/div[2]/div[2]/div/div[1]/div[3]/div[3]/div[1]/div[3]/div")).click();

        Thread.sleep(2000);
        WebElement fram = driver.findElement(By.xpath("/html/body/div[3]/div[2]/iframe[2]"));

        driver.switchTo().frame(fram);

        Thread.sleep(2000);

        driver.findElement(By.id("Fun2115Btn")).click();//公募产品设计

        driver.switchTo().defaultContent();

        Set<String> winHandels = driver.getWindowHandles(); // 得到当前窗口的set集合

        List<String> it = new ArrayList<String>(winHandels); // 将set集合存入list对象

        driver.switchTo().window(it.get(1)); // 切换到弹出的募产品设计新窗口

        Thread.sleep(1000);

        String url = driver.getCurrentUrl(); //获取新窗口的url

        System.out.println(url);

        //driver.switchTo().window(it.get(0)); // 返回至原页面

        Thread.sleep(3000);
        driver.findElement(By.id("fullname")).sendKeys(new String[]{"heqq公募产品设计0704"});

        Thread.sleep(1000);
        driver.findElement(By.id("fundname")).sendKeys(new String[]{"heqq公募产品设计0704"});//输入基金简称

        driver.findElement(By.id("fundcode")).sendKeys(new String[]{"100600"});//输入基金代码

        driver.findElement(By.xpath("//*[@id=\"flow-form\"]/div/div[2]/div[2]/div/div[3]/div[17]/div[1]/div/button")).click();//境内托管行

        Thread.sleep(2000);
        driver.findElement(By.xpath("//*[@id=\"flow-form\"]/div/div[2]/div[2]/div/div[3]/div[17]/div[1]/div/div/ul/li[18]/a")).click();

        driver.findElement(By.xpath("//*[@id=\"flow-form\"]/div/div[2]/div[2]/div/div[3]/div[17]/div[2]/div/button")).click();//境外托管行

        Thread.sleep(2000);
        driver.findElement(By.xpath("//*[@id=\"flow-form\"]/div/div[2]/div[2]/div/div[3]/div[17]/div[2]/div/div/ul/li[2]/a")).click();
        //选择投资区域为 境内+港通股
        Select tzSelect = new Select(driver.findElement(By.xpath("//*[@id=\"flow-form\"]/div/div[2]/div[2]/div/div[3]/div[18]/div[1]/select")));
        tzSelect.selectByIndex(4);
        //选择基金类型为指数型
        Select jjSelect = new Select(driver.findElement(By.xpath("//*[@id=\"flow-form\"]/div/div[2]/div[2]/div/div[3]/div[18]/div[2]/select")));
        jjSelect.selectByIndex(2);
        //选择运作类型为定期开放
        Select yzSelect = new Select(driver.findElement(By.xpath("//*[@id=\"flow-form\"]/div/div[2]/div[2]/div/div[3]/div[19]/div[1]/select")));
        yzSelect.selectByIndex(3);
        //选择投资类型为保本型
        Select tzfsSelect = new Select(driver.findElement(By.xpath("//*[@id=\"flow-form\"]/div/div[2]/div[2]/div/div[3]/div[19]/div[2]/select")));
        tzfsSelect.selectByIndex(3);
        //选择基金经理为张一格
        driver.findElement(By.xpath("//*[@id=\"flow-form\"]/div/div[2]/div[2]/div/div[3]/div[20]/div/div/button")).click();
        driver.findElement(By.xpath("//*[@id=\"flow-form\"]/div/div[2]/div[2]/div/div[3]/div[20]/div/div/div/ul/li[16]/a")).click();
        Thread.sleep(2000);
        //选择分红类型默认现金分红
        Select fhSelect = new Select(driver.findElement(By.xpath("//*[@id=\"flow-form\"]/div/div[2]/div[2]/div/div[3]/div[21]/div[2]/select")));
        fhSelect.selectByIndex(2);
        //选择客户类型为零售主导
        Select khlxSelect = new Select(driver.findElement(By.id("instorretail")));
        khlxSelect.selectByIndex(2);
        //输入产品期限为2月
        driver.findElement(By.id("fundlimit")).sendKeys(new String[]{"2"});
        driver.findElement(By.id("cgrade_1")).click();
        Thread.sleep(3500);
        driver.findElement(By.xpath("//*[@id=\"productInfo-listTable-add\"]")).click();

        Thread.sleep(1000);

        driver.findElement(By.xpath("//*[@id=\"productInfoModal\"]/div/div/div[2]/form/div[1]/div[1]/input")).sendKeys(new String[]{"A20001"});

        Thread.sleep(2000);
        driver.findElement(By.xpath("//*[@id=\"productInfoModal\"]/div/div/div[2]/form/div[1]/div[2]/input")).sendKeys(new String[]{"TEST基金"});

        Select fjlxSelect = new Select(driver.findElement(By.xpath("//*[@id=\"productInfoModal\"]/div/div/div[2]/form/div[2]/div[1]/select")));
        fjlxSelect.selectByIndex(2);

        Select fxdjSelect = new Select(driver.findElement(By.xpath("//*[@id=\"productInfoModal\"]/div/div/div[2]/form/div[2]/div[2]/select")));
        fxdjSelect.selectByIndex(3);

        Select jnssSelect = new Select(driver.findElement(By.xpath("//*[@id=\"productInfoModal\"]/div/div/div[2]/form/div[3]/div/select")));
        jnssSelect.selectByIndex(3);

        driver.findElement(By.id("productInfoModal-save")).click();

        driver.findElement(By.linkText("产品费用明细")).click();


        try {

            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    //将滚动条滚到适合的位置
    public static void setScroll(WebDriver driver,int height){
        try {
            String setscroll = "document.documentElement.scrollTop=" + height;

            JavascriptExecutor jse=(JavascriptExecutor) driver;
            jse.executeScript(setscroll);
        } catch (Exception e) {
            System.out.println("滚动失败==||");
        }
    }
}

